package com.imstlife.vending.utils;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.imstlife.vending.activity.BaseActivity;

/**
 * Created by lihaifeng on 17/2/24.
 */

public class NetUtil {

    private NetEvent event = BaseActivity.event;


    public static final int NETWORK_NONE = 0 ;
    public static  final int NETWORK_MOBILE = 1;
    public static final int NETWORK_WIFI = 0 ;

    public static  int getNetWorkState(Context context){


        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if(networkInfo!=null&&networkInfo.isConnected()){

            if(networkInfo.getType()==ConnectivityManager.TYPE_WIFI){
                return NETWORK_WIFI;
            }else if(networkInfo.getType()==ConnectivityManager.TYPE_MOBILE){
                return NETWORK_MOBILE;
            }

        }else{
            return NETWORK_NONE;
        }
        return NETWORK_NONE;

    }


    public  interface NetEvent{

       void onNetChange(int state);

    };



}
